<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_actions_block_MceFoldersAction extends m_backoffice_extends_Action
{
	public function execute()
	{
		$rootNode = m_backoffice_services_RootNodeService::getInstance()->getModuleRootNode("medias");
        $href = $this->getRequestParameter('href');

        $user = $this->getUserContext()->getUser();
        $this->setDisplayLang($user->getBackLang());

        if(!is_null($href) && $href != '')
        {
            $explode = explode('/', $href);

            if(count($explode) == 2)
            {
                $nodeLang = $explode[0];
                $nodeId = $explode[1];
            }
            else
            {
                f_core_Routing::getInstance()->setRequestURL($href);

                $nodeLang = $this->getRequestParameter('docLang');
                $nodeId = $this->getRequestParameter('docId');
            }
        }
        else
        {
            $nodeId = $rootNode->getUniqueId();
            $nodeLang = $this->getContextLang();
        }

        try
        {
            $folders = m_backoffice_services_MenuService::getInstance()->getMenuTree('medias', $nodeId, $nodeLang);
        }
        catch(Exception $e)
        {
            $nodeId = $rootNode->getUniqueId();
            $nodeLang = $this->getContextLang();
            $folders = m_backoffice_services_MenuService::getInstance()->getMenuTree('medias', $nodeId, $nodeLang);
        }

		$this->addToModel("module", 'medias');
		$this->addToModel("nodes", $folders);
		
		$this->setView('success');
	}	
}